package com.demo.common;

import java.util.Deque;
import java.util.concurrent.ConcurrentLinkedDeque;

/**
 * Created by jie on 2017/3/2.
 */
public class RoutDbKit {
    /**
     * 存储数据库名栈
     * <p>
     * expr
     * size
     * value
     */

    private static final ThreadLocal<Deque<String>> threadLocal = new ThreadLocal<Deque<String>>() {
        @Override
        protected Deque<String> initialValue() {
            return new ConcurrentLinkedDeque<String>();
        }
    };

    public static String getDbName() {
        Deque<String> queue = threadLocal.get();
        return queue.peekFirst();
    }

    public static void setDbName(String value) {
        Deque<String> queue = threadLocal.get();
        queue.addFirst(value);
    }

    public static void removeDb() {
        Deque<String> queue = threadLocal.get();
        queue.removeFirst();
    }
}
